package com.hitqz.robot.biz.flow.component.agv;

import cn.hutool.json.JSONObject;
import com.hitqz.robot.biz.flow.domain.constant.FlowConstant;
import com.hitqz.robot.biz.flow.util.LiteFlowUtil;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;

/**
 * @author xupkun
 * @date 2025/2/26
 */
@Slf4j
@LiteflowComponent(value = "DispatchOtherTask", name = "[轮对/轮轴]呼叫AGV其他任务")
@AllArgsConstructor
public class DispatchOtherTask extends NodeComponent {

    private final RestTemplate restTemplate;

    @Override
    public void process() throws Exception {
        LiteFlowUtil.checkInterruptFlag();
        String key = FlowConstant.NODE_CUSTOM_INFO_MAP.get(this.getNodeId()).getParamNames().get(0);
        String uri = this.getCmpData(JSONObject.class).get(key, String.class);
        //String uri = "http://127.0.0.1:9999/admin/km/agv/call?src=&des=&data=";
        log.info("请求其他台AGV任务分配:" + uri);
        try {
            String result = restTemplate.postForObject(
                    uri, "", String.class);
            log.info("请求其他台AGV任务分配:" + result);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }



}
